<template>
	<view class="content" style="padding-top: 20rpx;" :style="list.length>5?'':'height:100vh'">
		<view class="tab-scroll_box">
			<!-- 选项卡类别列表 -->
			<view class="tab-scroll_item" v-for=" (item, index) in tablist" :key="index"
				:class="{ 'tabzhon': tabindex == index }" @click="tabcli(index)">
				{{ item.name }}
			</view>
		</view>
		<view class="mt20">
			<view class="mian mb20" v-for="(item,index) in list" :key="index" @click.stop="jump(item)">
				<view class="dis_f aic jub">
					<view class="dis_f aic fs28">
						<text>订单编号 ：</text>
						<text class="c9">{{item.order_sn}}</text>
					</view>

					<text class="fs30" style="color: #feb746;">{{item.status_cn}}</text>
				</view>
				<view class="dis_f  mt20 ">
					<image :src="item.submsg.img" mode="aspectFill" class="listimg"></image>
					<view class="ml20" style="width: 78%;">
						<view class="fs26">
							{{item.submsg.main_title}}
						</view>
						<view class="dis_f aic jub mt10">

							<view class=" fs26 c9">
								×1
							</view>
						</view>
						<view class="dis_f aic jub">
							<view class=" fs26 cred">
								¥{{item.payment_price}}
							</view>
							<view class="dis_f aic">
								<view class="bunli dis_f aic juc mr20" v-if="item.status == 0"
									@click.stop="zhifu(item.id)">
									立即付款
								</view>
								<view class="bunli dis_f aic juc mr20" style="border: 1px solid #ccc; color: #ccc !important;" v-if="item.status == 0"
									@click.stop="quxiao(item.id)">
									取消订单
								</view>
								<button type="default" open-type="contact" class="bunli dis_f aic juc" v-if="item.status != 0">
									<view>
										联系客服
									</view>
								</button>
							</view>

						</view>
					</view>
				</view>
			</view>
			<view class="dis_f juc cac fs26" style="padding: 30rpx;" v-if="list.length == 0">
				暂无数据
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabindex: 0,
				list: [],
				tablist: [{
						name: '全部订单',
					}, {
						name: '待付款',
					},
					{
						name: '待取货',
					},
					{
						name: '已完成',
					},

				],
				page: 1,
				pageConten: 0,
				loadstatus: '上拉加载更多',
				code: ''
			}
		},
		onLoad(option) {
			this.tabindex = option.status
		},
		onShow() {
			this.list = []
			this.page = 1
			this.postlist()
		},
		onReachBottom() {
			if (this.page < this.pageConten) {
				this.page++
				this.postlist()
			} else if (this.page == this.pageConten) {
				this.loadstatus = '没有更多了'
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.list = []
			this.page = 1
			this.postlist()
			uni.stopPullDownRefresh(); //停止刷新
			// this.xialashow = true
		},
		methods: {
			quxiao(id) {
				this.api.post('order/orderCancel', {
					id: id,
				}).then(res => {
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							title: '取消成功',
							icon: "none"
						})
						this.list = []
						this.page = 1
						this.postlist()
					}
			
			
				})
			},
			piingj(id) {
				uni.redirectTo({
					url: '/pagesA/my_user_subcomment/my_user_subcomment?type=' + 0 + '&id=' + id
				})
			},
			zhifu(id) {
				let that = this
				wx.login({
					success: async (res) => {
						that.code = res.code
						uni.setStorageSync("code", res.code);
						that.api.post('order/getorderpay', {
							id: id,
							code: that.code
						}).then(res => {
							console.log(res);
							if (res.code == 200) {
								uni.requestPayment({
									provider: 'wxpay', // 服务提提供商
									timeStamp: res.data.timeStamp, // 时间戳 142326201502031615
									nonceStr: res.data.nonceStr, // 随机字符串
									package: res.data.package,
									signType: res.data.signType, // 签名算法
									paySign: res.data.paySign, // 签名
									success: function(res) {
										console.log('支付成功', res);
										uni.showToast({
											title: '支付成功',
											icon: "none"
										})
										setTimeout(function() {
											that.list = []
											that.page = 1
											that.postlist()
										}, 1000)
										// 业务逻辑。。。
									},
									fail: function(err) {
										console.log('支付失败', err);
									}
								});

							}


						})
					}
				})


			},
			queren(id) {
				let that = this
				this.api.post('order/orderqrsh', {
					id: id,
				}).then(res => {
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							title: '签收完成',
							icon: "none"
						})
						setTimeout(function() {
							that.list = []
							that.page = 1
							that.postlist()
						}, 1000)
					}


				})
			},
			postlist() {

				this.api.post('order/orderlst', {
					page: this.page,
					size: 10,
					type: this.tabindex
				}).then(res => {
					console.log(res);
					if (res.code == 200) {

						this.pageConten = res.ext.pageCount
						this.list = this.list.concat(res.data);
						this.page >= this.pageConten ? this.loadstatus = '没有更多了' : this.loadstatus = '上拉加载更多'


					}


				})
			},
			jump(item) {
				uni.navigateTo({
					url: '/pagesA/my_user_orderdet/my_user_orderdet?id=' + item.id
				})
			},
			tabcli(index) {
				this.tabindex = index
				this.list = []
				this.page = 1
				this.postlist()
			},

		}
	}
</script>

<style lang="scss">
	.bunli {
		width: 142rpx;
		height: 55rpx;
		border: 1px solid #feb746;
		border-radius: 60rpx;
		font-size: 26rpx;
		color: #feb746 !important;
	}


	.tab-scroll_box {
		display: flex;
		align-items: center;
		flex-wrap: nowrap;
		box-sizing: border-box;
		justify-content: space-between;
		padding: 0 55rpx;
		width: 100%;

		.tab-scroll_item {
			flex-shrink: 0;
			padding-bottom: 10rpx;
			font-size: 30rpx;
		}
	}


	.btnsty {
		width: 123rpx;
		height: 46rpx;
		border: 1px solid #BDBDBD;
		border-radius: 8rpx;
		font-size: 26rpx;
		color: #969696;
		margin-top: 88rpx;
	}

	.listimg {
		width: 140rpx;
		height: 140rpx;
	}

	.mian {
		background-color: #fff;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.tabzhon {
		position: relative;
		color: #feb746;
		font-size: 28rpx;
		font-weight: bold;
	}

	.tabzhon:before {
		content: '';
		position: absolute;
		bottom: -6px;
		width: 97rpx;
		height: 2px;
		background-color: #feb746;
		transform: translateX(-50%);
		left: 50%;
	}

	.tab {
		font-size: 28rpx;
	}
</style>